<?php

/**
 * Warlock is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 *
 * @package    warlock
 * @author     David Cole <neophyte@sourcetutor.com>
 * @license    GNU/GPL v2
 */

// Module Dependencies
using('Library.Widgets.Form');
using('Library.Widgets.RecordSet');

class Module_Admin_warlock extends Admin_IModule
{
    var $_Name  = 'warlock';
    var $_Title = 'Warlock';
    
    /**#@+
     * Required Core Objects
     *
     * These are references to the core objects required by this
     * class.
     *
     * @access private
     * @var    object
     */
    var $_Error;
    var $_Profiler;
    var $_DAL;
    var $_Model;
    var $_Module;
    var $_User;
    /**#@-*/

    function __construct()
    {
        // Get references to required objects
        $this->_Error     = &Vault::Get('Debug_Error');
        $this->_Profiler  = &Vault::Get('Debug_Profiling');
        $this->_DAL       = &Vault::Get('DAL');
        $this->_Model     = &Vault::Get('Model');
        $this->_Module    = &Vault::Get('Module');
        $this->_User      = &Vault::Get('User');

        // Quick list of warlock modules, common actions, notices etc
        $this->RegisterAction(array('panel'), 'Control Panel', 'ControlPanel_List');
        
        // Call Admin_IModule constructor (we call it last so it has access to the actions array)
        parent::__construct();        
    }


    function ControlPanel_List()
    {
        $dh    = opendir(W_ENV_PATH.'/Extensions/Admin/');
		$items = array();
        
        while (($file = readdir($dh)) !== false)
        {            
            if (($file != '.') && ($file != '..') && ($file != 'warlock') && file_exists(W_ENV_PATH.'/Extensions/Admin/'.$file.'/module.php'))
            {            
                if ($this->_User->HasAccess($file.'_'.$file))
                {                               
                    $module  = &$this->_Module->Get('Admin', $file);
    
                    $items['website'][] = array('name'        => $module->_Name,
                                                'title'       => $module->_Title,
                                                'description' => '',
                                                'url'         => W_ENV_URL.'/admin/module;'.$module->_Name.'/');
                                           

                }
            }
        }

        closedir($dh);
        
        $this->_Model->Body('module', $items, 'controlpanel', 'warlock');
    }
}

?>